//
//  CZBaseTableViewController.swift
//  weibo
//
//  Created by Ken on 16/3/21.
//  Copyright © 2016年 Ken. All rights reserved.
//

import UIKit

class CZBaseTableViewController: UITableViewController {
    ///用户是否登录
    var userLogin = CZUserAccountViewModel.sharedInstance.userLogin
    
    override func loadView() {
        userLogin ? super.loadView() :setupVisitorView()
    }

    ///设置访客视图
    func setupVisitorView() {
        view = visitorView
        
        visitorView.delegate = self
        
        if (self is CZHomeViewController) {
            visitorView.startRotation()
        }else if (self is CZMessageViewController) {
            visitorView.setupVisitor("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        } else if (self is CZDiscoverViewController) {
            visitorView.setupVisitor("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        } else if (self is CZProfileViewController) {
            visitorView.setupVisitor("visitordiscover_image_profile", message: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
        
        //navigationItem
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册",style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidClickRegisterButton")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "visitroViewDidClickLoginButton")
        
    }
    
    // MARK: - 懒加载
    ///自定义的访客视图
    
    lazy var visitorView: CZVisitorView = CZVisitorView()
}


//MARK: - extension扩展,可以在扩展里面实现协议,方便代码管理
extension CZBaseTableViewController: CZVisitorViewDelegate{
    
    var name: String{
        get {
            return ""
        }
        set {
            
        }
    }
    
    // MARK: - 实现协议的方法
    //6 实现协议的方法
    func visitorViewDidClickRegisterButton() {
        
    }
    
    func visitroViewDidClickLoginButton() {
        // 弹出登陆界面
        let oauthVC = CZOauthViewController()
        
        // Modal出控制器
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }

}
